#include "qdialogprogress.h"
#include "ui_qdialogprogress.h"

QDialogProgress::QDialogProgress(QWidget *parent) :
    QBaseDialog(parent,Qt::CustomizeWindowHint | Qt::WindowTitleHint),
    ui(new Ui::QDialogProgress)
{
    ui->setupUi(this);
}

QDialogProgress::~QDialogProgress()
{
    delete ui;
}

void QDialogProgress::set_max(int max)
{
    ui->progressBar->setRange(-1,max);
    ui->label->setVisible(max>0);
    set_value(0);
}

void QDialogProgress::set_value(int value)
{
    if(ui->progressBar->maximum()>0)
    {
        QString str;
        str.sprintf("%0.2f%%",value*100.0/ui->progressBar->maximum());
        ui->label->setText(str);
        setWindowTitle(str);
    }
    else
    {
        setWindowTitle(tr("Warting"));
    }
    ui->progressBar->setValue(value);
}
